/**
 * @description 订单model
 * @author liyunfu
 */

const mongoose = require("../db/db");

const Schema = mongoose.Schema(
  {
    username: { type: String, require: true }, //必须
    shopId: String,
    shopName: String,

    idCanceled: {
      type: Boolean,
      default: false,
    },
    address: {
      username: String,
      city: String,
      department: String,
      houseNumber: String,
      name: String,
      phone: String,
    },
    products: [
      {
        product: {
          shopId: {
            type: String,
            require: true,
          },
          name: String,
          imgUrl: String,
          sales: Number,
          price: Number,
          oldPrice: Number,
          tabs: [String],
        },
        orderSales: Number,
      },
    ],
  },
  { timestamps: true }
);

const Order = mongoose.model("order", Schema);

module.exports = Order;
